"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebSocketClientManager = void 0;
const WebSocketClient_1 = require("./WebSocketClient");
const SocketClientReqManager_1 = require("./SocketClientReqManager");
class WebSocketClientManager {
    constructor() {
        this.onlyId = 0;
        this.webSocketClientMap = new Map();
    }
    getWebSocketClientByServerConfig(serverConfig) {
        let client;
        if (this.webSocketClientMap.has(serverConfig.getInternalWsUrl())) {
            client = this.webSocketClientMap.get(serverConfig.getInternalWsUrl());
        }
        else {
            client = this.createSocketClientByServerConfig(serverConfig);
            SocketClientReqManager_1.SocketClientReqManager.instance.req_server_internal_Login(serverConfig);
        }
        return client;
    }
    createSocketClientByServerConfig(serverConfig) {
        let url = serverConfig.getInternalWsUrl();
        let webSocketClient = this.createSocketClient(url);
        this.webSocketClientMap.set(url, webSocketClient);
        return webSocketClient;
    }
    createSocketClient(url) {
        this.onlyId++;
        let webSocketClient = new WebSocketClient_1.WebSocketClient();
        webSocketClient.init(url, this.onlyId);
        return webSocketClient;
    }
    destoyWebSocketClient(webSocketClient) {
        this.webSocketClientMap.delete(webSocketClient.url);
        webSocketClient.close();
        webSocketClient.destroy();
        webSocketClient = null;
    }
}
exports.WebSocketClientManager = WebSocketClientManager;
WebSocketClientManager.instance = new WebSocketClientManager();
